<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
    <style>
        .layui-form-item .layui-input-inline {
            width: 150px;
        }
        .layui-form-label {
            padding: 9px 5px;
            width: auto;
        }
        .layui-btn_a {
            display: inline-block;
            height: 38px;
            line-height: 38px;
            padding: 0 18px;
            white-space: nowrap;
            text-align: center;
            font-size: 14px;
            border: 1px solid #e6e6e6;
            border-radius: 2px;
            cursor: pointer;
        }

        .thisColor {
            background-color: #009688;
            color: #fff;
            border: none;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <form class="layui-form" id="sbumitForm">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline ">
                        <input type="hidden" name="type_1" value="2" id="type_1" />
                        <label class="layui-form-label">达人榜名称</label>
                        <div class="layui-input-inline" style="width: 120px">
                            <select name="type_0">
                                <option value="1">主播达人榜</option>
                                <option value="2">富豪达人榜</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline ">
                        <label class="layui-form-label">用户ID</label>
                        <div class="layui-input-inline">
                            <input type="text" name="uid" placeholder="请输入用户ID" autocomplete="off" class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-inline" style="width:80px;">
                        <div class="layui-input-inline" style="width:80px;">
                            <div class="layui-btn" id="submit">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </div>
                        </div>
                    </div>
                    <div class="layui-inline" style="width:80px;">
                        <div class="layui-input-inline" style="width:80px;">
                            <div class="layui-btn" onclick="conf()">活动说明配置</div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-inline">
                            <div class="layui-btn_a" onclick="formSubmit(1,this)">
                                昨日榜单
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn_a thisColor" onclick="formSubmit(2,this)">
                                今日榜单
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn_a" onclick="formSubmit(3,this)">
                                上周榜单
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn_a" onclick="formSubmit(4,this)">
                                本周榜单
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn_a" onclick="formSubmit(5, this)">
                                上月榜单
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn_a" onclick="formSubmit(6, this)">
                                本月榜单
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>

        <div class="layui-card-body layui-table-body layui-table-main">
            <table id="demo" lay-filter="demo"></table>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    var titles = <?php echo $titles;?>;
    layui.config({
        base: "/layuiadmin/" //静态资源所在路径
    }).extend({
        index: "lib/index", //主入口模块
    }).use(["table",'form'], function () {
        $ = layui.jquery, form = layui.form, table = layui.table;
        $("#submit").click(function () {
            table.render(table_conf());
        });

        table.render(table_conf());
    });

    function table_conf() {
        return  {
            elem: '#demo',
            id: '#demo',
            url: '/admin/talent/index?' + $("#sbumitForm").serialize(),
            defaultToolbar: [
                'filter','print',{title:'提示',layEvent: 'LAYTABLE_EXCEL',icon: 'layui-icon-table'},
            ],
            page: {
                curr: 1   //默认从第一页开始搜索
            },
            method: "get",
            //where: $("#sbumitForm").serialize(),
            limit: 20,
            limits: [20, 30, 50, 100, 200, 500],
            text: {
                none: '暂无相关数据！'//默认无数据
            },
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 0,//成功的状态码，默认：0
                msgName: 'msg', //状态信息的字段名称，默认：msg
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'list', //数据列表的字段名称，默认：data
            },
            cols: [[
                {field: 'id', width: 80, title: 'ID', sort: true, align: 'center'},
                {field: '', width: 160, title: '达人榜名称', align: 'center',templet: function (item) {
                        if (titles[item.top_type_0]) {
                            return titles[item.top_type_0];
                        }

                        return '';
                    }
                },
                {field: 'title', width: 130, title: '达人榜类型', align: 'center', templet: function (item) {
                        var type = '';
                        switch (item.top_type_1) {
                            case 1:
                                type = '日榜';
                                break;
                            case 2:
                                type = '周榜';
                                break;
                            case 3:
                                type = '月榜';
                                break;
                        }

                        return type;
                    }
                },
                {field: 'uid', width: 140, title: '用户ID', align: 'center'},
                {field: 'title', width: 220, title: '用户昵称', align: 'center', templet: function (item) {
                        if (item.user) {
                            return item.user.nick_name;
                        }
                        return '';
                    }
                },
                {field: 'title', title: '用户类型', align: 'center', templet: function (item) {
                        if (item.user) {
                            switch (item.user.is_anchor) {
                                case 0:
                                    if (item.user.anchor_type == 3) {
                                        return '<span class="layui-badge layui-bg-orange">测试用户</span>';
                                    }
                                    return '<span class="layui-badge layui-bg-orange">用户</span>';
                            }
                            var html = "";
                            switch (item.user.anchor_type) {
                                case 1:
                                    html = '<span class="layui-badge layui-bg-green">主播</span>';
                                    break;
                                case 2:
                                    html = '<span class="layui-badge layui-bg-red">公司主播</span>';
                                    break;
                                case 3:
                                    html = '<span class="layui-badge layui-bg-red">测试主播</span>';
                                    break;
                            }

                            return html;
                        }
                        return '';
                    }
                },
                {field: 'fans', width: 150, title: '粉丝', align: 'center'},
                {field: 'diamond', width: 150, title: '贡献值', align: 'center'},
            ]],
            done: function (res, curr, count) {
                res.list.forEach(function (item, index) {

                });
            },
        };
    }

    /**配置*/
    function conf() {
        layer.open({
            type: 2,
            title: ["达人榜配置", 'font-size:16px'],
            content: '/admin/talent/conf',
            area: ['620px', '450px'],
            //offset: '0px',
        });
    }

    function edit(id, type) {
        layer.open({
            type: 2,
            title: ["编辑", 'font-size:16px'],
            content: '/admin/talent/edit?id=' + id + '&type=' + type,
            area: ['560px', '430px'],
            //offset: '0px',
        });
    }

    function add() {
        layer.open({
            type: 2,
            title: ["添加", 'font-size:16px'],
            content: '/admin/talent/add',
            area: ['560px', '430px'],
            //offset: '0px',
        });
    }
    
    function formSubmit(type, obj) {
        if (type == $("#type_1").val()) {
            return false;
        }

        $(".layui-btn_a").each(function(){
            $(this).removeClass('thisColor');
        });

        $("#type_1").val(type);
        $(obj).addClass('thisColor');
        layui.table.render(table_conf());
    }
</script>
</body>
</html>
